package com.orange.cetback.controller.user;

import com.orange.cetback.common.vo.PageResult;
import com.orange.cetback.common.vo.Result;
import com.orange.cetback.pojo.dto.AnswerRecordDTO;
import com.orange.cetback.pojo.dto.UserAnswerRecordDTO;
import com.orange.cetback.pojo.entity.UserAnswerRecord;
import com.orange.cetback.pojo.vo.UserAnswerRecordVO;
import com.orange.cetback.service.UserAnswerRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenenjun
 * @since 2025-03-05
 */
@Tag(name = "用户答题记录")
@RestController
@RequestMapping("/userApi/userAnswerRecord")
public class UserAnswerRecordController {
    @Autowired
    private UserAnswerRecordService userAnswerRecordService;

    @Operation(summary = "保存用户答题记录")
    @PostMapping("/saveUserAnswerRecord")
    public Result<UserAnswerRecord> saveUserAnswerRecord(@RequestBody UserAnswerRecordDTO userAnswerRecordDTO) {
        UserAnswerRecord userAnswerRecord = userAnswerRecordService.saveUserAnswerRecord(userAnswerRecordDTO);
        return Result.success(userAnswerRecord);
    }

    @Operation(summary = "根据记录ID查询答题记录")
    @GetMapping("/getAnswerRecord/{recordId}")
    public Result<UserAnswerRecordVO> getAnswerRecord(@PathVariable("recordId") Long recordId) {
        UserAnswerRecordVO userAnswerRecordVO = userAnswerRecordService.getAnswerRecord(recordId);
        return Result.success(userAnswerRecordVO);
    }

    @Operation(summary = "分页查询做题记录")
    @GetMapping("/page")
    public Result<PageResult<UserAnswerRecordVO>> page(AnswerRecordDTO answerRecordDTO){
        PageResult<UserAnswerRecordVO> pageResult = userAnswerRecordService.pageQuery(answerRecordDTO);
        return Result.success(pageResult);
    }
}
